package com.yanqu.road.server.cross3server.cmd.xrank.season;

import com.yanqu.road.entity.rank.xrank.XSeasonUserRank;
import com.yanqu.road.logic.pb.XRankPb;
import com.yanqu.road.logic.xlogic.rank.season.XSeasonUserRankChangeParam;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.XRankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.cross3server.manager.Cross3XRankMgr;
import com.yanqu.road.server.protocol.Cross3Protocol;

import java.util.List;

@Cmd(code = Cross3Protocol.C3_XRANK_UPLOAD_SEASON_USER_RANK_FROM_GAME, desc = "游戏服 上传赛季个人榜")
public class XRankUploadSeasonUserRankFromGameCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        boolean needSync = true;
        if (getClass().getSimpleName().equals("XRankSyncSeasonUserRankFromChannelCmd")) {
            needSync = false;
        }

        XRankProto.XSeasonUserRankListMsg reqMsg = XRankProto.XSeasonUserRankListMsg.parseFrom(packet.getBytes());
        int systemId = reqMsg.getSystemId();
        int seasonId = reqMsg.getSeasonId();
        int type = reqMsg.getType();
        String rangeKey = reqMsg.getRangeKey();
        List<XRankProto.XUserRankMsg> rankMsgList = reqMsg.getRankListList();
        for (XRankProto.XUserRankMsg rankMsg : rankMsgList) {
            XSeasonUserRank userRank = XRankPb.parseXSeasonUserRank(systemId, seasonId, type, rangeKey, rankMsg);
            Cross3XRankMgr.getSeasonUserRankMap().userRankChange(userRank, new XSeasonUserRankChangeParam(needSync, true, rankMsg.getBaseInfo()));
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData() {

    }
}
